package com.lq.educationsystem.lqclasses.controller;


import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.vo.ClassesPageVo;
import com.lq.educationsystem.lqclasses.entiy.ClassesTb;
import com.lq.educationsystem.lqclasses.service.ClassesBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Tag(name = "班级信息")
@RequestMapping("/classes/base")
@RestController
public class ClassesBaseController {
    @Autowired
    ClassesBaseService classesBaseService;

    //增加

    @Operation(summary = "插入课程信息")
    @PostMapping("/insert")
    public Result insertClassesInfo(@RequestBody ClassesTb classesInfo){
        classesBaseService.insertInfo(classesInfo);
        return ResultBuild.buildOk();
    }
    //删除
    @Operation(summary = "通过课程id删除课程信息")
    @PostMapping("/delete")
    public Result deleteClassesById(@RequestBody ClassesTb classesInfo){
        //删除
        Integer classesId = classesInfo.getClassesId();
        classesBaseService.deleteById(classesId);
        return ResultBuild.buildOk();

    }
    //更新
    @Operation(summary = "更新班级信息")
    @PostMapping("/update")
    public Result updateClassesInfo(@RequestBody ClassesTb classesInfo){

        classesBaseService.updateInfo(classesInfo);
        return ResultBuild.buildOk();
    }
    //通过id查询
    @Operation(summary = "通过课程id查询课程信息")
    @PostMapping("/querybyid")
    public Result<ClassesTb> queryClassesById(@RequestBody ClassesTb classesInfo){
        Integer classesId = classesInfo.getClassesId();
        Result result= classesBaseService.queryById(classesId);
        //通过id查询


        return result;
    }

    @Operation(summary = "分页查询课程信息")
    @PostMapping("/query")
    public ResultPage<ClassesTb> queryClasses(@RequestBody ClassesPageVo classesInfo) {
        //查询语句
        ResultPage<ClassesTb>  classesTbResultPage= classesBaseService.queryList(classesInfo);

        return classesTbResultPage;
    }

    /**
     * 批量查询班级信息
     */

    @Operation(summary = "通过课程id集合批量查询课程信息")
    @PostMapping("/query/batch/classes")
    public ResultPage<ClassesTb> queryClassesInfoByClassesId(@RequestBody List<Integer> classesIdList) {

        ResultPage<ClassesTb> resultPage = classesBaseService.queryClassesInfoByClassesId(classesIdList);

        return resultPage;
    }
}
